package cn.school.mybatis.service;

import cn.school.mybatis.dao.GradeDao;
import cn.school.mybatis.pojo.Grade;
import cn.school.mybatis.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//业务逻辑bean
//服务层,调用dao方法
public class GradeService {

    public final static GradeService GRADE_SERVICE = new GradeService();

//增加
public int add(Grade grade) {
    SqlSession session = MyBatisUtil.getSqlSession();
    try {
        GradeDao Gradedao = session.getMapper(GradeDao.class);
        return Gradedao.add(grade);
    } finally {
        session.commit();
        MyBatisUtil.close(session);
    }
}
//删除
public int del(int id) {
    SqlSession session = MyBatisUtil.getSqlSession();
    try {
        GradeDao dao = session.getMapper(GradeDao.class);
        return dao.del(id);
    } finally {
        session.commit();
        MyBatisUtil.close(session);
    }
}
//修改
public int update(Grade grade) {
    SqlSession session = MyBatisUtil.getSqlSession();
    try {
        GradeDao dao = session.getMapper(GradeDao.class);
        return dao.update(grade);
    } finally {
        session.commit();
        MyBatisUtil.close(session);
    }
}
//id查单个
public Grade get(int id) {
    SqlSession session = MyBatisUtil.getSqlSession();
    try {
        GradeDao dao = session.getMapper(GradeDao.class);
        return dao.get(id);
    } finally {
        MyBatisUtil.close(session);
    }
}


//查全部
public List<Grade> searchAll() {
    SqlSession session = MyBatisUtil.getSqlSession();
    try {
        GradeDao dao = session.getMapper(GradeDao.class);
        return dao.searchAll();
    } finally {
        MyBatisUtil.close(session);
    }
}




}
